package com.rd.student.ruanjian.class3.gaochenxi.LianXI5;

import java.io.*;
import java.util.LinkedList;
import java.util.Random;

public class DaLeTou {
   public static void main(String[] args) {
//      Func();
//      Fun2();
      LinkedList list = Fun2();
      Fun3(list);
   }

   public static void Func() {
      //随机一组数字,怎么存储到daletou.txt中呢?
      StringBuilder stringBuilder = new StringBuilder();
      int[] quchong = QUCHONG();//前5个数
      int[] quchong2 = QUCHONG2();//后两个数
      String daletou = "";
      for (int i = 0; i < quchong.length; i++) {
         String s = String.valueOf(quchong[i] + " ");
         stringBuilder.append(s);
      }
      stringBuilder.append("| ");
      for (int i = 0; i < quchong2.length; i++) {
         String s = String.valueOf(quchong2[i] + " ");
         stringBuilder.append(s);
      }
      System.out.println(stringBuilder.toString());


      File file = new File("daletou.txt");
      if (!file.exists()) {
         try {
            file.createNewFile();
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }

      try {
         FileWriter fileWriter = new FileWriter("daletou.txt");
         fileWriter.write(String.valueOf(stringBuilder));
         fileWriter.close();
      } catch (FileNotFoundException e) {
         throw new RuntimeException(e);
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
   }

   public static LinkedList Fun2() {
      LinkedList<String> list = new LinkedList();
      for (int j = 0; j < 100; j++) {
         StringBuilder stringBuilder = new StringBuilder();
         int[] quchong = QUCHONG();//前五个数
         int[] quchong2 = QUCHONG2();//后两个数
         String daletou = "";
         for (int i = 0; i < quchong.length; i++) {
            String s = String.valueOf(quchong[i] + " ");
            stringBuilder.append(s);
         }
         stringBuilder.append("| ");
         for (int i = 0; i < quchong2.length; i++) {
            String s = String.valueOf(quchong2[i] + " ");
            stringBuilder.append(s);
         }
         list.add(String.valueOf(stringBuilder));
         File file = new File("randomDLT.txt");
         if (!file.exists()) {
            try {
               file.createNewFile();
            } catch (IOException e) {
               throw new RuntimeException(e);
            }
         }

         try {
            FileWriter fileWriter = new FileWriter("randomDLT.txt", true);
            fileWriter.write(String.valueOf(stringBuilder) + "\t" + "\n");
            fileWriter.close();
         } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }
      return list;
   }

   public static void Fun3(LinkedList<String> list) {
      try {
         File file = new File("daletou.txt");
         File file1 = new File("randomDLT.txt");
         FileReader fileReader = new FileReader(file);
         FileWriter fileWriter = new FileWriter(file1);
         String daletou = "";//file的内容
         char[] chars = new char[1024];
         daletou = String.valueOf(fileReader.read(chars));//daletou里面的字符
         int count = 0;
         for (int i = 0; i < Fun2().size(); i++) {
            if (Fun2().get(i).equals(daletou)) {
               count++;
            }
         }
         System.out.println("中奖个数为:" + count + "个");
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
   }

   public static int[] QUCHONG() {
      int min = 1;
      int max = 35;
      int[] arr = new int[5];
      Random random = new Random();
      for (int i = 0; i < arr.length; i++) {
         int randoms = min + random.nextInt(max - min);
         arr[i] = randoms;
         for (int j = 0; j < i; j++) {
            if (arr[j] == arr[i]) {
               i--;
               break;
            }
         }
      }
      return arr;
   }

   public static int[] QUCHONG2() {
      int min = 1;
      int max = 12;
      int[] arr = new int[2];
      Random random = new Random();
      for (int i = 0; i < arr.length; i++) {
         int randoms = min + random.nextInt(max - min);
         arr[i] = randoms;
         for (int j = 0; j < i; j++) {
            if (arr[j] == arr[i]) {
               i--;
               break;
            }
         }
      }
      return arr;
   }
}
